package cn.liyicun.school.car2.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;

import cn.liyicun.school.car2.base.BaseUserController;

public class UserLoginInterceptor implements Interceptor {

	@Override
	public void intercept(Invocation inv) {

		if (inv.getController() instanceof BaseUserController) {
			BaseUserController line = (BaseUserController) inv.getController();
			if ("POST".equalsIgnoreCase(line.getRequest().getMethod())) {
				line.getLoginAccount();
			} else {
				if (line.getLoginAccount(false) == null) {
					line.redirect301("/user/login?nologin", false);
					return;
				}
			}

		}
		inv.invoke();
	}

}
